class Combinations
  include Singleton
  
  def initialize
    clear
  end
  
  def clear
    @combinations_by_transition = Hash.new([])
    @combinations_by_case = Hash.new([])
  end
  
  #:transition, :tokens
  def add(options)
    if(transition = options[:transition])
      if transition.kind_of?(PNEngine::Transition)
        @combinations_by_transition[transition.id] += [Combination.new(:tokens => options[:tokens])]
      else
        @combinations_by_transition[transition.to_i] += [Combination.new(:tokens => options[:tokens])]
      end
    end
  end
  
  #token
  def destroy_all(options)
    @combinations_by_transition.each do |transition, combinations|
      combinations.each do |combination|
        @combinations_by_transition[transition].delete(combination) if combination.tokens.include?(options[:token])
      end
    end
  end
  
  #:transition, :tokens
  def find(options)
    if(transition = options[:transition])
      if transition.kind_of?(PNEngine::Transition)
        return @combinations_by_transition[transition.id].collect{|comb| comb.tokens}
      else
        return @combinations_by_transition[transition.to_i].collect{|comb| comb.tokens}
      end
    end
  end
end

class Combination
  attr_accessor :tokens

  def initialize(options = {:tokens => []})
    @tokens = options[:tokens]
  end
end